Hennepin County Tidycensus Map

Author

Can Zhang

Date and Time: 2023-04-11 00:12:40

Hennepin County Tidycensus Map

options(tigris_use_cache = TRUE)
hennepin_pop_inc.df <- get_acs(
  geography = "tract",
  variables = c("B01003_001E","B19013_001"), #Code for total population and median income
  state     = "MN",
  county    = "Hennepin",
  year      = 2020,
  geometry  = TRUE,
  cb        = FALSE
) %>%
  janitor::clean_names() 
Warning: • You have not set a Census API key. Users without a key are limited to 500
queries per day and may experience performance limitations.
ℹ For best results, get a Census API key at
http://api.census.gov/data/key_signup.html and then supply the key to the
`census_api_key()` function to use it throughout your tidycensus session.
This warning is displayed once per session.

  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |                                                                      |   1%
  |                                                                            
  |=                                                                     |   1%
  |                                                                            
  |=                                                                     |   2%
  |                                                                            
  |==                                                                    |   2%
  |                                                                            
  |==                                                                    |   3%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |===                                                                   |   5%
  |                                                                            
  |====                                                                  |   5%
  |                                                                            
  |====                                                                  |   6%
  |                                                                            
  |=====                                                                 |   6%
  |                                                                            
  |=====                                                                 |   7%
  |                                                                            
  |=====                                                                 |   8%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |======                                                                |   9%
  |                                                                            
  |=======                                                               |   9%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |========                                                              |  11%
  |                                                                            
  |========                                                              |  12%
  |                                                                            
  |=========                                                             |  13%
  |                                                                            
  |==========                                                            |  14%
  |                                                                            
  |==========                                                            |  15%
  |                                                                            
  |===========                                                           |  15%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |=============                                                         |  19%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |====================                                                  |  28%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |===========================                                           |  38%
  |                                                                            
  |===============================                                       |  44%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |=======================================                               |  55%
  |                                                                            
  |===========================================                           |  61%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |================================================                      |  68%
  |                                                                            
  |====================================================                  |  74%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |===========================================================           |  85%
  |                                                                            
  |===============================================================       |  91%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |=================================================================     |  93%
  |                                                                            
  |==================================================================    |  94%
  |                                                                            
  |==================================================================    |  95%
  |                                                                            
  |======================================================================| 100%
hennepin_pop.df <- hennepin_pop_inc.df %>% filter(variable=="B01003_001")

hennepin_pop.gg <-  hennepin_pop.df %>%
  mutate(
    tract  = str_split(name, ",") %>%
      map_chr(1) %>%
      str_remove("Census Tract "),
    text_label = str_c(
      "Tract: ",
      tract,
      "\nPopulation: ",
      round(estimate/ 1000, 0), 
      " K"
    )
  ) %>%
  ggplot() + 
  geom_sf( aes(fill = estimate,text = text_label),alpha=0.8) + 
  labs(title = "2020 US Census Population Estimates for Hennepin") + 
  theme_void() + 
  scale_fill_viridis_c("Population")
Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
: Ignoring unknown aesthetics: text
ggplotly(hennepin_pop.gg, tooltip = "text") %>%
  style(hoveron = "fills")